<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\model\adminModel;
use think\facade\Request;
use think\facade\Validate;
use think\facade\View;

class admin
{
    public function adminList()
    {
        $adminList = adminModel::select();
        View::assign('adminList',$adminList);
        return View::fetch('admin/adminList');
    }

    public function delete()
    {
        $admin_id = Request::param('admin_id');
        $validate = Validate::rule([
            'admin_id|管理员id' => 'require|between:1,'.PHP_INT_MAX,
        ]);

        if(!$validate->check(['admin_id'=>$admin_id])){
            echo $validate->getError();
            exit();
        }
        $result = adminModel::destroy($admin_id);

        if ($result) {
            echo "<script>alert('删除成功');</script>";
            echo "<script>location.href='/index.php?s=admin/admin/adminList'</script>";
        } else {
            echo "<script>alert('删除失败,请联系管理员：1292888678@qq.com');</script>";
        }
    }
}
